// Pci7230.cpp: implementation of the CPci7230 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "HGLaser.h"
#include "Pci7230.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
CPci7230::CPci7230()
{
    card_number=0;
    card=1;
	input=0; 
	output=0;
	oldinput=0 ;
}

CPci7230::~CPci7230()
{
    if (card >= 0) Release_Card(card);
}

void CPci7230::Cardinit()
{
	if ((card=Register_Card(PCI_7230, card_number)) < 0)
	{
		CString str;
		str.Format(_T("Register_Card Error = %d\n"), card);
		AfxMessageBox(str);
	}
}

I16 __stdcall  CPci7230::Int1(BOOL state,HANDLE windowHandle,unsigned long message,void *callbackAddr())
{
	if(state)
	return DIO_INT1_EventMessage (card, INT1_EXT_SIGNAL,windowHandle,message,callbackAddr);
    else
	return DIO_INT1_EventMessage (card, INT1_DISABLE,windowHandle,message,callbackAddr);
}

void CPci7230::Int2(BOOL state,HANDLE windowHandle,unsigned long message,void *callbackAddr())
{
	if(state)
	DIO_INT2_EventMessage (card, INT2_EXT_SIGNAL,windowHandle,message,callbackAddr);
    else
	DIO_INT2_EventMessage (card, INT2_DISABLE,windowHandle,message,callbackAddr);
}

BOOL CPci7230::DataInput(int num)
{
    DI_ReadPort(card,0,&input);
	if ((input>>num)&0x01)
		return TRUE;
	else
		return FALSE;			    		
}

void  CPci7230::Dataoutput(int num,bool flag)
{
	if(flag)
        output = (((U32)1L)<<num)|output;
	else
		output = ~(((U32)1L)<<num)&output;	
	 DO_WritePort(card,0, output);
}

void CPci7230::Release()
{
	if (card >= 0) 
		Release_Card(card);
}

#ifdef __cplusplus
}
#endif